package com.woniuxy.service.impl;

import com.woniuxy.dao.RbacManagerDao;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.service.RbacManagerservice;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RbacManagerserviceImpl implements RbacManagerservice {
    @Autowired(required = false)
    RbacManagerDao rbacManagerDao;
    @Override
    public RbacManager findOne(int id) {
       return rbacManagerDao.findOne(id);
    }

    @Override
    @Cacheable(value = "cache")
    public List<RbacManager> findAll() {
        return rbacManagerDao.findAll();
    }

    @Override
    public int delete(int id) {
        return rbacManagerDao.delete(id);
    }

    @Override
    public int addOne(RbacManager rbacManager) {
        //提供，新增用户时候的，密码加密功能！
        String password = rbacManager.getPassword();
        //就是一个加密算法，别人写好的，中间的password，是目标被加密的对象，最后的一个参数是salt 盐 (加密结果收到盐的影响)
        SimpleHash simpleHash = new SimpleHash("MD5", password, rbacManager.getAccount()+"woniuxy");
        String newPassword = simpleHash.toHex();//转成16进制字符串
        rbacManager.setPassword(newPassword);
        return rbacManagerDao.addOne(rbacManager);
    }

    @Override
    public int updateOne(RbacManager rbacManager) {
        return rbacManagerDao.updateOne(rbacManager);
    }
}
